package com.egg.basic.util;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.mail.Mail;
import cn.hutool.extra.mail.MailAccount;

import java.util.List;

/**
 * 邮箱 工具类
 *
 * @author east
 */
public class EmailUtil {


    private static MailAccount mailAccountClient;


    public void setMailAccount(MailAccount mailAccount) {
        mailAccountClient = mailAccount;
    }

    public static void send(
            List<String> tos
            , String title
            , String content
    ) {
        send(tos, title, content, false);
    }

    public static void send(
            List<String> tos
            , String title
            , String content
            , Boolean isHtml
    ) {
        if (null == mailAccountClient) {
            throw new RuntimeException("未初始化邮箱客户端");
        }
        if (ObjectUtil.isEmpty(tos)
                || ObjectUtil.isEmpty(title)
                || ObjectUtil.isEmpty(content)
        ) {
            return;
        }
        Mail mail = Mail.create(mailAccountClient);
        mail.setTos(tos.toArray(new String[0]));
        mail.setTitle(title);
        mail.setContent(content);
        mail.setHtml(isHtml);
        mail.send();
    }

}